// @/api/modules/space.ts
import { Space } from "@/api/interface/space";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

// 获取分组列表
export const getGroupListApi = () => {
  return http.get<Space.GroupList>(PORT1 + `/group/getGroupList`);
};

// 新增分组
export const addGroupApi = (params: Space.GroupAddParams) => {
  return http.post(PORT1 + `/group/addGroup`, params);
};

// 编辑分组
export const updateGroupApi = (params: Space.GroupUpdateParams) => {
  return http.post(PORT1 + `/group/updateGroup`, params);
};

// 删除分组
export const deleteGroupApi = (params: { FId: number }) => {
  return http.post(PORT1 + `/group/deleteGroup`, params);
};

// 获取空间列表
export const getSpaceListByGroupApi = (params?: { FGroupId?: number; FUserId?: string }) => {
  return http.get<Space.SpaceList>(PORT1 + `/space/getSpaceListByGroup`, params);
};

// 搜索空间
export const searchSpaceApi = (params: { FKeyword: string; FUserId?: string }) => {
  return http.get<Space.SpaceList>(PORT1 + `/space/searchSpace`, params);
};

// 创建空间
export const createSpaceApi = (params: Space.CreateSpaceParams) => {
  return http.post<Space.SpaceItem>(PORT1 + `/space/createSpace`, params);
};

// 编辑空间
export const updateSpaceApi = (params: Space.UpdateSpaceParams) => {
  return http.post(PORT1 + `/space/updateSpace`, params);
};

// 删除空间
export const deleteSpaceApi = (params: { FId: string }) => {
  return http.post(PORT1 + `/space/deleteSpace`, params);
};

// 收藏/取消收藏
export const toggleFavoriteApi = (params: Space.ToggleFavoriteParams) => {
  return http.post<{ FIsStarred: boolean }>(PORT1 + `/space/toggleFavorite`, params);
};

// 获取空间详情
export const getSpaceDetailApi = (params: { FId: string }) => {
  return http.get<Space.SpaceDetail>(PORT1 + `/space/getSpaceDetail`, params);
};

/**
 * 添加空间管理员
 * @param params {Space.AddSpaceAdminParams}
 * @returns
 */
export const addSpaceAdminApi = (params: Space.AddSpaceAdminParams) => {
  return http.post(PORT1 + `/space/addAdmin`, params);
};

/**
 * 移除空间管理员
 * @param params {Space.RemoveSpaceAdminParams}
 * @returns
 */
export const removeSpaceAdminApi = (params: Space.RemoveSpaceAdminParams) => {
  return http.post(PORT1 + `/space/removeAdmin`, params);
};

/**
 * 获取空间管理员列表
 * @param params {Space.GetSpaceAdminsParams}
 * @returns {Promise<Space.SpaceAdminList>}
 */
export const getSpaceAdminsApi = (params: Space.GetSpaceAdminsParams) => {
  return http.get<Space.SpaceAdminList>(PORT1 + `/space/getAdmins`, params, {
    loading: false
  });
};

/**
 * 检查用户是否是空间管理员
 * @param params {Space.CheckAdminParams}
 * @returns {Promise<Space.CheckAdminResult>}
 */
export const checkSpaceAdminApi = (params: Space.CheckAdminParams) => {
  return http.get<Space.CheckAdminResult>(PORT1 + `/space/checkAdmin`, params);
};
